package objects;

import java.util.*;

public class Event implements Comparable<Event> {

	private String DETAILS;
	private String TAG;
	private int PRIORITY;
	protected Calendar STARTDATE;
	protected Calendar ENDDATE;
	protected SortedEventList SUBTASKS;

	public Event(String PARAM_DETAILS, String PARAM_TAG, int PARAM_PRIORITY,
			Calendar PARAM_STARTDATE, Calendar PARAM_ENDDATE, SortedEventList PARAM_SUBTASK) {
		DETAILS = PARAM_DETAILS;
		TAG = PARAM_TAG.toLowerCase();
		PRIORITY = PARAM_PRIORITY;
		STARTDATE = PARAM_STARTDATE;
		ENDDATE = PARAM_ENDDATE;
		SUBTASKS = PARAM_SUBTASK;
	}
	
	public Event(){
		Calendar TEMP_DATE = new GregorianCalendar();
		DETAILS = null;
		TAG = null;
		PRIORITY = -1;
		STARTDATE = TEMP_DATE;
		ENDDATE = TEMP_DATE;
		SUBTASKS = null;
	}

	public boolean equals(Object obj) {
		if (obj instanceof Event) {
			Event x = (Event) obj;
			if (DETAILS.equals(x.getDetails()) && TAG.equals(x.getTag())
					&& PRIORITY == x.getPriority() && STARTDATE.equals(x.getStartDate()) && ENDDATE.equals(x.getEndDate())) {
				return true;
			} else {
				return false;
			}
		}
		return super.equals(obj);
	}
	
	@Override
	public int compareTo(Event x) {
		// TODO Auto-generated method stub
		if (DETAILS.equals(x.getDetails()) && TAG.equals(x.getTag())
				&& PRIORITY == x.getPriority() && STARTDATE.equals(x.getStartDate()) && ENDDATE.equals(x.getEndDate())) {
			return 0;
		}
		else if (ENDDATE.compareTo(x.getEndDate()) < 0 
				|| ENDDATE.equals(x.getEndDate()) && STARTDATE.compareTo(x.getStartDate())<0
				|| (ENDDATE.equals(x.getEndDate()) && STARTDATE.equals(x.getStartDate()) && PRIORITY < x.getPriority())
				|| (ENDDATE.equals(x.getEndDate()) && STARTDATE.equals(x.getStartDate()) && PRIORITY == x.getPriority() && TAG
						.compareTo(x.getTag()) < 0)
				|| (ENDDATE.equals(x.getEndDate()) && STARTDATE.equals(x.getStartDate()) && PRIORITY == x.getPriority()
						&& TAG.equals(x.getTag()) && DETAILS.compareTo(x
						.getDetails()) < 0)) {
			return -1;
		} else
			return 1;
	}

	public String getDetails() {
		return DETAILS;
	}

	public String getTag() {
		return TAG;
	}

	public int getPriority() {
		return PRIORITY;
	}

	public Calendar getStartDate() {
		return STARTDATE;
	}
	
	public Calendar getEndDate(){
		return ENDDATE;
	}
	
	public SortedEventList getSubTasks(){
		return SUBTASKS;
	}
	
	protected void setSubTask(int x, SortedEventList e, Event y){
		e.set(x, y);
	}
	


	protected void setStartDate(Calendar d) {
		STARTDATE = d;
	}
	
	protected void setEndDate(Calendar d){
		ENDDATE = d;
	}

	protected void setDetails(String s) {
		DETAILS = s;
	}

	protected void setTag(String t) {
		TAG = t;
	}

	protected void setPriority(int b) {
		PRIORITY = b;
	}

	

}
